﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace DiscreteMath.Tests
{
    /// <summary>
    /// A class used for generating test devices.
    /// </summary>
    public abstract class TestFactory<T>
    {
        /// <summary>
        /// Gets a collection of all tests defined in the factory.
        /// </summary>
        /// <returns></returns>
        public IEnumerable<TestableDevice<T>> GetAllTests()
        {
            var factoryType = this.GetType();
            var deviceType = typeof(TestableDevice<T>);
            ICollection<TestableDevice<T>> devices = new List<TestableDevice<T>>();
            foreach (PropertyInfo property in factoryType.GetProperties())
            {
                if (property.PropertyType.IsSubclassOf(deviceType))
                    devices.Add(property.GetValue(this) as TestableDevice<T>);
            }
            return devices;
        }
    }
}
